<!DOCTYPE html>
<html>
<head>
	<title>javascript非对称加密(RSA)JSEncrypt Example</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script type="text/javascript" src="../dist/webencrypt.min.js"></script>
</head>
<body>

<div class="container">
	<h1>javascript非对称加密(RSA)</h1>
	<label for="privkey">私钥</label><br/>
	<textarea id="privkey" rows="5" cols="35">-----BEGIN RSA PRIVATE  KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
	<label for="pubkey">公钥</label><br/>
	<textarea id="pubkey" rows="5" cols="35">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
	
	<div class="tool">
		输入需要加密文字：<br/>
		<textarea name="" id="needCrypt" cols="30" rows="3">天明v587</textarea>
		<a href="javascript:void(0);" id="crypt-btn">加密</a><br/>
		加密结果：<br/>
		<textarea name="" id="resultCrypt" cols="30" rows="10">
  </textarea>
		<a href="javascript:void(0);" id="decrypt-btn">解密</a><br/>
		解密结果：<br/>
		<textarea name="" id="result" cols="30" rows="3">
  </textarea>
	</div>
	
	<script type="text/javascript">
		
		// Call this code when the page is done loading.
		$(function() {
			$("#crypt-btn").click(function(){
				// Encrypt with the public key...
				var encrypt = window.webEncrypt;
				var encrypted = encrypt.rsa_encrypt($('#pubkey').val(), $("#needCrypt").val());
				document.getElementById("resultCrypt").innerText = encrypted;
			});
			$("#decrypt-btn").click(function(){
				// Decrypt with the private key...
				var decrypt = window.webEncrypt;
				var uncrypted = decrypt.rsa_decrypt($('#privkey').val(), $("#resultCrypt").val());
				document.getElementById("result").innerText = uncrypted;
			});
		});
	</script>

</div>
</body>
</html>
